import { inject, injectable } from "tsyringe";
import { Request, IRequest } from "./tokens";
import { ForbiddenError } from "./error";
export interface IUser {
    uid: string;
    username: string;
    password: string;
}
@injectable()
export class User {
    public readonly token?: string;
    public errors: Error[] = [];
    constructor(@inject(Request) req: IRequest) {
        const { headers } = req;
        const authorization = headers.authorization;
        if (authorization) {
            const [bearer, token] = authorization.split(' ')
            if (!['Bearer'].includes(bearer)) {
                this.errors.push(new ForbiddenError({ reason: '非法 Authorization,请使用 Bearer+空格+token' }))
            }
            this.token = token;
        }
    }
    async needPermission(permission: string): Promise<boolean> {
        return true;
    }

    async fetchUserInfo(): Promise<IUser> {
        throw new Error(`method not implement`)
    }
}